from pyspark import SparkConf
from pyspark import SparkContext

if __name__ == '__main__':
    conf = SparkConf().setMaster("local[2]").setAppName("wordcount")
    sc = SparkContext(conf=conf)

    s = 0
    # 所有单词的总数
    lines = sc.textFile("../data/test1.txt")
    words = lines.flatMap(lambda line: line.split(","))


    def sum_numbers(w):
        print(w)
        global s
        s += 1
        print(s)

    words.foreach(sum_numbers)

    print(s)
